package com.ruoyi.scheme.controller;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.scheme.dto.ErsPatchAttributesDto;
import com.ruoyi.scheme.dto.MixSchemeRequest;
import com.ruoyi.scheme.dto.SingleSchemeRequest;
import com.ruoyi.scheme.service.decision.DecisionMakingService;
import com.ruoyi.scheme.vo.DecisionMakingVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 智能决策制定接口
 */
@RestController
@RequestMapping("/divisionMaking")
public class DecisionMakingController {

    @Autowired
    private DecisionMakingService decisionMakingService;

    /**
     * 根据斑块属性生成生态修复方案（基础规则和部分默认规则）
     * @param patchAttributesDto
     * @return
     */
    @PostMapping("/generateDefaultScheme")
    @DataSource(DataSourceType.SLAVE)
    @ApiOperation("根据斑块属性生成生态修复方案")
    public R<DecisionMakingVO> generateScheme(
            @RequestParam @NotNull Integer optMeasures,                  //选择的可选型措施
            @RequestParam @NotNull Integer patchId,
            @RequestBody @NotNull ErsPatchAttributesDto patchAttributesDto) {
        return R.ok(decisionMakingService.generateDefaultScheme(patchId, optMeasures, patchAttributesDto));
    }

    /**
     * 生成扩展规则中的自由配置型措施
     * 单作播种
     */
    @PostMapping("/singleScheme")
    @DataSource(DataSourceType.SLAVE)
    @ApiOperation("生成草料单作播种生态修复方案")
    public R<DecisionMakingVO> singleScheme(@RequestBody @NotNull SingleSchemeRequest request){
        ErsPatchAttributesDto patchAttributesDto = request.getPatchAttributesDto();
        String plantName = request.getPlantName();
        Integer schemeId = request.getSchemeId();
        return R.ok(decisionMakingService.singleGrassScheme(patchAttributesDto, plantName, schemeId));
    }

    /**
     * 生成扩展规则中的自由配置型措施
     * 混播播种
     */
    @PostMapping("/mixScheme")
    @DataSource(DataSourceType.SLAVE)
    @ApiOperation("生成草料混播播种生态修复方案")
    public R<DecisionMakingVO> mixScheme(@RequestBody @NotNull MixSchemeRequest request){
        return R.ok(decisionMakingService.mixGrassScheme(
                request.getPatchAttributesDto(),
                request.getPlantMix(),
                request.getSchemeId()));
    }
}
